#include <iostream>
#include <string>
#include <chrono>
#include "yolov3_clip_detector.h"
using namespace std;

int main()
{
    //const char * g_omModelPath = "/home/HwHiAiUser/xjl_learn/20241230/resource_optical_clip_detector_dynamic/model/googlenet_dynamicbatch.om";
    const char * g_omModelPath = "../model/cliptiny_dynamic.om";
    Yolov3CLIPDetector sampleProcess;
    size_t batchsize = 2;
    bool ret = sampleProcess.Initialize(g_omModelPath, batchsize);
    if (ret != true) {
        std::cout<<"sample init resource failed"<<std::endl;
        return 0;
    }
    vector<cv::Mat> imglist;
    for (int i=0; i< batchsize; i++){
    	cv::Mat img1 = cv::imread("../data/1.jpg");
    	imglist.push_back(img1);
    }

    for (int i=0; i<120; i++){
    	ret = sampleProcess.inference(imglist);
    	if (ret != true) {
		std::cout<<"sample process failed"<<static_cast<int32_t>(ret)<<std::endl;
        	return 0;
    	}
    }
    
    int sum_times =0;
    for (int i=0; i<100; i++){
        std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
        ret = sampleProcess.inference(imglist);
        std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
        if (ret != true) {
            std::cout<<"222222:  sample process failed"<<std::endl;
            return 0;
        }
        std::chrono::duration<double, std::milli> time_span = t2 - t1;
        std::cout << "It took " << time_span.count() << " milliseconds."<<std::endl;
        sum_times += time_span.count();
    }
    std::cout<<"100 iters average time: "<<1.0 * sum_times/100<<std::endl;
    std::cout<<"execute sample success"<<std::endl;
    return 1;
}
